﻿using Commons.Requests;
using Commons.ReturnData;
using Microsoft.AspNetCore.Mvc;
using OpenAI.Domain.Entities;
using OpenAI.Infrastructure.Requests;
using OpenAI.Infrastructure.Services;
using OpenAI.WebAPI.Filters;

namespace OpenAI.WebAPI.Controllers
{
    [ApiController]
    [Area("OpenAI")]
    [Route("[area]/[controller]/[action]")]
    [TypeFilter(typeof(InitFilter))]
    public class ChatSessionController:ControllerBase
    {
        public readonly ChatSessionService chatSessionService;
        public Guid AppUserId { get; set; }

        public ChatSessionController(ChatSessionService chatSessionService)
        {
            this.chatSessionService = chatSessionService;
        }

        [HttpPost]
        public async Task<MessageResult> CreateChatSessionAsync(ChatSessionRequest chatSessionRequest)
        {
            chatSessionRequest.AppUserId = AppUserId;
            return await chatSessionService.CreateChatSessionAsync(chatSessionRequest);
        }

        [HttpGet]
        public async Task<DataResult<ChatSession>> GetChatSessionByUserIdAsync([FromQuery] PagingRequest pagingRequest)
        {
            return await chatSessionService.GetChatSessionsByUserIdAsync(AppUserId, pagingRequest);
        }

        [HttpPost]
        public async Task<MessageResult> UpdateChatSessionAsync(ChatSessionRequest chatSessionRequest)
        {
            return await chatSessionService.UpdateChatSessionAsync(chatSessionRequest);
        }

        [HttpDelete]
        public async Task<MessageResult> DeleteChatSessionByIdAsync(int id)
        {
            return await chatSessionService.DeletedChatSessionAsync(AppUserId, id);
        }

    }
}
